package com.os.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.math.Fraction;

import com.os.model.FoodX;
import com.os.service.ReferFoodServiceX;
import com.os.serviceimpl.ReferFoodServiceImpX;

import net.sf.json.JSONObject;

public class SelectFoodsStateControllerX extends HttpServlet{
	ReferFoodServiceX fao = new ReferFoodServiceImpX();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		StringBuffer fs = new StringBuffer(); 
		String fids = req.getParameter("fids");
		String [] fidss = fids.split("fid=");
		for (int i = 0; i < fidss.length; i++) {
			fs.append(fidss[i]);
		}
		String newFidss = fs.toString();
		String [] newFids = newFidss.split("&");
		/*for (int i = 0; i < newFids.length; i++) {
			System.out.println(newFids[i]);
		}*/
		List<FoodX> fstates = fao.selectFnameAndfhasmaByIds(newFids);
		PrintWriter pw = resp.getWriter();
		JSONObject  json = new JSONObject();
		json.put("fstates",fstates);
		pw.write(json.toString());

	}
}
